/**
 *  This file is part of OhSnap.
 *
 * 	Copyright (c) 2009 Gabriel Mendonça and Marcelo Machado
 * 
 *  OhSnap is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OhSnap is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OhSnap.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */
package br.mm.midi;

import javax.sound.midi.ShortMessage;

/**
 * @author mendonça
 * 
 */
public class MidiNote {

	private Note note;
	private int octave;
	private int velocity;

	/**
	 * Constructor.
	 * 
	 * @param shortMessage
	 *            a NOTE_ON short message
	 */
	public MidiNote(ShortMessage message) {
		setNote(Note.getNote(message.getData1()));
		setOctave(getOctave(message.getData1()));
		setVelocity(message.getData2());
	}

	/**
	 * Returns the octave of the given MIDI message.
	 * 
	 * @param data
	 *            the first data byte of the MIDI message
	 * @return the octave of the given MIDI message.
	 */
	private int getOctave(int data) {
		return (data / 12) - 1;
	}

	/**
	 * @param note
	 *            the note to set
	 */
	public void setNote(Note note) {
		this.note = note;
	}

	/**
	 * @return the note
	 */
	public Note getNote() {
		return note;
	}

	/**
	 * @param octave
	 *            the octave to set
	 */
	public void setOctave(int octave) {
		this.octave = octave;
	}

	/**
	 * @return the octave
	 */
	public int getOctave() {
		return octave;
	}

	/**
	 * @param velocity
	 *            the velocity to set
	 */
	public void setVelocity(int velocity) {
		this.velocity = velocity;
	}

	/**
	 * @return the velocity
	 */
	public int getVelocity() {
		return velocity;
	}

}
